package com.dgut.smart_house.controller;

import com.dgut.smart_house.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
public class LoginController {

    @RequestMapping({"/toLogin", "/"})
    public String toLogin() {
        return "login";
    }


    @RequestMapping("/noAuth")
    public String noAuth() {
        return "noAuth";
    }


    @RequestMapping("/index")
    public String index() {
        return "index";
    }


    @RequestMapping("/toRegister")
    public String toRegister() {
        return "register";
    }


    @RequestMapping("/signOut")
    public String signOut() {
        Subject subject = SecurityUtils.getSubject();
        log.info("用户-{}-退出登录了", ((User) subject.getPrincipal()).getUserId());
        subject.logout();
        return "redirect:/toLogin";
    }
}
